const SessionRepositories = require('../repositories/sessionRepositiories')

class SessionServices {

  handleResponse(data, error, notFoundMessage = '实体未找到') {
    if (error) {
      return {
        code: 1,
        msg: error.message,
        statusCode: error.statusCode || 500
      }
    }
    if (!data) {
    return {
      code: 1,
      msg: notFoundMessage,
      statusCode: 404,
    };
  }
    return { code: 0, data: data }
  }

  async getSessionByUserId(userid) {
    const session = await SessionRepositories.getSessionByUserId(userid)
    return this.handleResponse(session, null, null)
  }
}

module.exports = new SessionServices